package Service.Impl;

import Dao.CartDao;
import Dao.Impl.CartDaoImpl;
import Domain.Cart;
import Domain.Product;
import Service.CartService;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class CartServiceImpl implements CartService {
    private CartDao dao = new CartDaoImpl();
    @Override
    public List<Cart> FindCartByUserid(int id) {
        return dao.FindCartByUserid(id);
    }

    @Override
    public void DelCartItem(int id) {
        dao.DelCartItem(id);
    }

    @Override
    public void AddCart(int uid, int pid, Double price) {
        dao.AddCart(uid,pid,price);
    }

    @Override
    public List<Cart> FindCartItemById(int id) {
        return dao.FindCartItemById(id);
    }

    @Override
    public void UpdateCartItemNumById(int id, int num , Double total) {
        dao.UpdateCartItemNumById(id,num,total);
    }

    @Override
    public List<Cart> getCarts(String[] ids) {
        CartService service=new CartServiceImpl();
        List<Cart> ps = new ArrayList<>();
        Cart c=new Cart();
        if (ids != null && ids.length > 0) {
            for (String id : ids) {
                c=dao.FindCartItemById(Integer.parseInt(id)).get(0);
                ps.add(c);
            }

        }
        return ps;
    }



    @Override
    public List<Cart> getCarts(String[] ids) {
        CartService service=new CartServiceImpl();
        List<Cart> ps = new ArrayList<>();
       Cart c=new Cart();
        if (ids != null && ids.length > 0) {
            for (String id : ids) {
                c=dao.FindCartItemById(Integer.parseInt(id)).get(0);
                ps.add(c);
            }

        }
        return ps;
    }






}
